$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'orth/teamInfo/list',
        datatype: "json",
        colModel: [
            { label: 'ID', name: 'id_', index: "id_", width: 35, key: true },
            { label: '类型', name: 'type', width: 80, formatter: function(value, options, row){
                 switch(value)
				 {
					 case "1":return "关节修复与重建";
                     case "2":return "关节翻修";
                     case "3":return "下肢畸形矫正";
                     case "4":return "骨与关节感染";
                     case "5":return "风湿关节病";
					 default: return "";
				 }
            }},
            { label: '更新时间', name: 'updateTime', width: 80,sortable:false}
        ],
        viewrecords: true,

        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    $('.form-horizontal').validationEngine('attach',{
        autoHidePrompt: true,
        autoHideDelay: 2000,
        maxErrorsPerField: 1
    });
});

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            title: null
        },
        showList: true,
        title:null,
        teamInfo:{
            status:0
        },
        items:[{text:'关节修复与重建',value:'1'},{text:'关节翻修',value:'2'},{text:'下肢畸形矫正',value:'3'},{text:'骨与关节感染',value:'4'},{text:'风湿关节病',value:'5'}]
    },
    methods: {
        query: function () {
            vm.reload();
        },
        update: function () {
            var userId = getSelectedRow();
            if(userId == null){
                return ;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getUser(userId);

        },
        saveOrUpdate: function () {


            if(!$(".form-horizontal").validationEngine("validate")) {
                $(".formError").show();
                return;
            }
            /*if(vm.validator()){
                return ;
            }*/
            vm.teamInfo.teamRange=um_range.getContent();
            vm.teamInfo.learning=um_learn.getContent();

            var reg1 = new RegExp( '<' , "g" );
            var reg2 = new RegExp( '>' , "g" );

            if(vm.teamInfo.teamRange!=null && vm.teamInfo.teamRange.length>0)
            {

                vm.teamInfo.teamRange=vm.teamInfo.teamRange.replace( reg1,'88888888qzpm' );
                vm.teamInfo.teamRange=vm.teamInfo.teamRange.replace( reg2,'99999999qzpm' );
            }

            if(vm.teamInfo.learning!=null && vm.teamInfo.learning.length>0)
            {
                vm.teamInfo.learning=vm.teamInfo.learning.replace( reg1,'88888888qzpm' );
                vm.teamInfo.learning=vm.teamInfo.learning.replace( reg2,'99999999qzpm' );
            }


            var url ="orth/teamInfo/update";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.teamInfo),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        getUser: function(id){
            $.get(baseURL + "orth/teamInfo/info/"+id, function(r){
                vm.teamInfo = r.teamInfo;
                um_range.setContent(vm.teamInfo.teamRange);
                um_learn.setContent(vm.teamInfo.learning);
            });
        },
        reload: function () {
            vm.showList = true;
            $(".formError").hide();
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'title': ""},
                page:page
            }).trigger("reloadGrid");
        },
        validator: function () {

        }
    }
});